﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using Microsoft.Windows.Controls.Ribbon;
using Microsoft.Windows.Controls;

namespace ScrumMagic
{
    /// <summary>
    /// Interaction logic for AllUsersList.xaml
    /// </summary>
    public partial class AllUsersList : ScrumMagic.CommonForm
    {
        private AllUsersRibbon AllUsersRibbon;

        public AllUsersList()
        {
            InitializeComponent();
            AllUsersRibbon = new AllUsersRibbon();
        }
        
        public override RibbonTab RibbonContextualTab
        {
            get
            {
                AllUsersRibbon.ribbonMenu.Tabs.Remove(AllUsersRibbon.tabEdit);
                return AllUsersRibbon.tabEdit;
            }
        }

        public override void OnActivated()
        {
            try
            {
                SqlCommand cmd = DBController.MainConnection.CreateCommand();
                cmd.CommandText = "Select Id, FirstName, MiddleName, LastName from dbo.[User]";
                cmd.CommandType = System.Data.CommandType.Text;
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                DataTable table = new DataTable();
                adapter.Fill(table);
                dataGrid.ItemsSource = table.DefaultView;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can't get table All Users",
                  "ScrumMagic",
                MessageBoxButton.OK);
            }

        }

        private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            // если наследовать от CommonForm
            if (dataGrid.SelectedItem == null)
                return;

            DataRowView SelectedRow = (DataRowView)dataGrid.SelectedItem;
            CommonForm UserCard = new UserCardForm((int)SelectedRow["Id"]);
            UserCard.Title = "User Card";
            FormController.OpenForm(UserCard, FormController.ContainerTypes.window);
            
            //если наследовать от Window
            //DataRowView SelectedRow = (DataRowView)dataGrid.SelectedItem;
            //UserCardForm UserCardForm = new UserCardForm(SelectedRow[0].ToString());
            //UserCardForm.Show();
        }
    }
}

